function T_t=costPlanner2(V_i,V_f,a,dist,dv)
% PURPOSE: Calculate the trip time for a interplanetary burn
%---------------------------------------------------
% USAGE: [FUNC_OUTPUTS] = FUNC_NAME(FUNC_INPUTS)
% WHERE: V_i = m/s = Initial velocity
%        V_f = m/s = Final velocity
%        a = G's = Acceleration of the drive
%        Dist = AUs = Distance to destination (relative to V_i)
%        dv = m/s = Total DV to be spent on velocity changes
%---------------------------------------------------
% RETURNS: T_t = Total time of manuver
% --------------------------------------------------
% SEE ALSO:
% --------------------------------------------------


%%
%---------------------------------------------------
% REFERENCES:
%---------------------------------------------------
% REMARKS:
%---------------------------------------------------
% UPDATES:
%	V1: Inital copy and changes. 
%---------------------------------------------------
% Written by: John M. Murray. 4/31/11
%---------------------------------------------------

%% Convert to SI
a=abs(a)*9.80665;
dist=dist*150e9;


%% Error Checking
% Check to see if given DV is enough
assert(dv-abs(V_f-V_i)>0,'Not enough DV for correction burn, add more DV');

%% Calculate Arrival DV
dv_cor=abs(V_f-V_i);

%% Calculate Departure/Arival Burns
V_trav=V_i+(dv-dv_cor)/2*sign(dist);

%% Calculate Travel Time
T_trav=dist/(V_trav-V_f);

%% Calculate Correction Time
T_cor=dv_cor/a;

%% Calculate Accel/Decel Time
T_ad=(dv-dv_cor)/a;

T_t=T_trav+T_ad*2+T_cor;

if(sign(V_f)==-1 && sign(dist)==-1)
	min_dv=abs(3*(V_f-V_i));
elseif(sign(V_f)==-1 && sign(dist)==1) 
	min_dv=abs(V_f-V_i);
elseif(sign(V_f)==1 && sign(dist)==-1)
	min_dv=abs(3*(V_f-V_i));
elseif(sign(V_f)==1 && sign(dist)==1) 
	min_dv=abs(V_f-V_i);
end

%% Final time checks
assert(sign(T_trav)==1,'Negative travel time, add more DV')
assert(T_trav~=Inf,'Infinate travel time, add more DV');

%% Ouput
fprintf('**Course Calculated!***\n');
fprintf('Planning:\n');
fprintf('   Min DV: %.2f (m/s)\n',min_dv);
fprintf('Stats:\n');
fprintf('  DV used in correction: %.2f\n',dv_cor);
fprintf('  DV used in Accel/Decel: %.2f\n',dv-dv_cor);
%%fprintf('Final Speed:\n   %.2f (m/s)\n',V_trav);
fprintf('Final closure speed:\n   %.2f (m/s)\n',abs(V_f-V_trav));
fprintf(['Time (accel):\n',time2str(T_ad)]);
fprintf(['Time (decel):\n',time2str(T_ad+T_cor)]);
fprintf(['Time (coast):\n',time2str(T_trav)]);
fprintf(['Time (total):\n',time2str(T_t)]);
end % End costPlanner2(...)



%% Math Work
%

%% 4 Cases
%

% V_i+ V_f+ Dist+
%	- 'Catch up' to planet if needed.
%	- Use remaining dv in a 50/50 split

% V_i+ V_f- Dist-
%	- 'Catch up' to planet if needed.
%	- Use remaining dv in a 50/50 split

% V_i+ V_f- Dist+
%	- Calculate arrival DV requirements
%	- Use remaining dv in a 50/50 split

% V_i+ V_f+ Dist-
%	- Calculate arrival DV requirements
%	- Use remaining dv in a 50/50 split
